<!DOCTYPE html>
<html lang="zh-CN" class="no-js">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="profile" href="http://gmpg.org/xfn/11">
		<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>
<title>if…else &#8211; 太极创客</title>
<link rel='dns-prefetch' href='//s.w.org' />
		<script>
			window._wpemojiSettings = {"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/12.0.0-1\/72x72\/","ext":".png","svgUrl":"https:\/\/s.w.org\/images\/core\/emoji\/12.0.0-1\/svg\/","svgExt":".svg","source":{"concatemoji":"http:\/\/www.taichi-maker.com\/wp-includes\/js\/wp-emoji-release.min.js?ver=5.4.4"}};
			/*! This file is auto-generated */
			!function(e,a,t){var r,n,o,i,p=a.createElement("canvas"),s=p.getContext&&p.getContext("2d");function c(e,t){var a=String.fromCharCode;s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,e),0,0);var r=p.toDataURL();return s.clearRect(0,0,p.width,p.height),s.fillText(a.apply(this,t),0,0),r===p.toDataURL()}function l(e){if(!s||!s.fillText)return!1;switch(s.textBaseline="top",s.font="600 32px Arial",e){case"flag":return!c([127987,65039,8205,9895,65039],[127987,65039,8203,9895,65039])&&(!c([55356,56826,55356,56819],[55356,56826,8203,55356,56819])&&!c([55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447],[55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447]));case"emoji":return!c([55357,56424,55356,57342,8205,55358,56605,8205,55357,56424,55356,57340],[55357,56424,55356,57342,8203,55358,56605,8203,55357,56424,55356,57340])}return!1}function d(e){var t=a.createElement("script");t.src=e,t.defer=t.type="text/javascript",a.getElementsByTagName("head")[0].appendChild(t)}for(i=Array("flag","emoji"),t.supports={everything:!0,everythingExceptFlag:!0},o=0;o<i.length;o++)t.supports[i[o]]=l(i[o]),t.supports.everything=t.supports.everything&&t.supports[i[o]],"flag"!==i[o]&&(t.supports.everythingExceptFlag=t.supports.everythingExceptFlag&&t.supports[i[o]]);t.supports.everythingExceptFlag=t.supports.everythingExceptFlag&&!t.supports.flag,t.DOMReady=!1,t.readyCallback=function(){t.DOMReady=!0},t.supports.everything||(n=function(){t.readyCallback()},a.addEventListener?(a.addEventListener("DOMContentLoaded",n,!1),e.addEventListener("load",n,!1)):(e.attachEvent("onload",n),a.attachEvent("onreadystatechange",function(){"complete"===a.readyState&&t.readyCallback()})),(r=t.source||{}).concatemoji?d(r.concatemoji):r.wpemoji&&r.twemoji&&(d(r.twemoji),d(r.wpemoji)))}(window,document,window._wpemojiSettings);
		</script>
		<style>
img.wp-smiley,
img.emoji {
	display: inline !important;
	border: none !important;
	box-shadow: none !important;
	height: 1em !important;
	width: 1em !important;
	margin: 0 .07em !important;
	vertical-align: -0.1em !important;
	background: none !important;
	padding: 0 !important;
}
</style>
	<link rel='stylesheet' id='crayon-css'  href="../wp-content/plugins/crayon-syntax-highlighter/css/min/crayon.min.css-ver=_2.7.2_beta.css" tppabs="http://www.taichi-maker.com/wp-content/plugins/crayon-syntax-highlighter/css/min/crayon.min.css?ver=_2.7.2_beta" media='all' />
<link rel='stylesheet' id='crayon-theme-arduino-ide-css'  href="../wp-content/plugins/crayon-syntax-highlighter/themes/arduino-ide/arduino-ide.css-ver=_2.7.2_beta.css" tppabs="http://www.taichi-maker.com/wp-content/plugins/crayon-syntax-highlighter/themes/arduino-ide/arduino-ide.css?ver=_2.7.2_beta" media='all' />
<link rel='stylesheet' id='crayon-font-monaco-css'  href="../wp-content/plugins/crayon-syntax-highlighter/fonts/monaco.css-ver=_2.7.2_beta.css" tppabs="http://www.taichi-maker.com/wp-content/plugins/crayon-syntax-highlighter/fonts/monaco.css?ver=_2.7.2_beta" media='all' />
<link rel='stylesheet' id='wp-block-library-css'  href="../wp-includes/css/dist/block-library/style.min.css-ver=5.4.4.css" tppabs="http://www.taichi-maker.com/wp-includes/css/dist/block-library/style.min.css?ver=5.4.4" media='all' />
<link rel='stylesheet' id='wp-block-library-theme-css'  href="../wp-includes/css/dist/block-library/theme.min.css-ver=5.4.4.css" tppabs="http://www.taichi-maker.com/wp-includes/css/dist/block-library/theme.min.css?ver=5.4.4" media='all' />
<link rel='stylesheet' id='genericons-css'  href="../wp-content/themes/twentysixteen/genericons/genericons.css-ver=3.4.1.css" tppabs="http://www.taichi-maker.com/wp-content/themes/twentysixteen/genericons/genericons.css?ver=3.4.1" media='all' />
<link rel='stylesheet' id='twentysixteen-style-css'  href="../wp-content/themes/twentysixteen/style.css-ver=20190507.css" tppabs="http://www.taichi-maker.com/wp-content/themes/twentysixteen/style.css?ver=20190507" media='all' />
<link rel='stylesheet' id='twentysixteen-block-style-css'  href="../wp-content/themes/twentysixteen/css/blocks.css-ver=20190102.css" tppabs="http://www.taichi-maker.com/wp-content/themes/twentysixteen/css/blocks.css?ver=20190102" media='all' />
<!--[if lt IE 10]>
<link rel='stylesheet' id='twentysixteen-ie-css'  href="../wp-content/themes/twentysixteen/css/ie.css-ver=20170530.css" tppabs="http://www.taichi-maker.com/wp-content/themes/twentysixteen/css/ie.css?ver=20170530" media='all' />
<![endif]-->
<!--[if lt IE 9]>
<link rel='stylesheet' id='twentysixteen-ie8-css'  href="../wp-content/themes/twentysixteen/css/ie8.css-ver=20170530.css" tppabs="http://www.taichi-maker.com/wp-content/themes/twentysixteen/css/ie8.css?ver=20170530" media='all' />
<![endif]-->
<!--[if lt IE 8]>
<link rel='stylesheet' id='twentysixteen-ie7-css'  href="../wp-content/themes/twentysixteen/css/ie7.css-ver=20170530.css" tppabs="http://www.taichi-maker.com/wp-content/themes/twentysixteen/css/ie7.css?ver=20170530" media='all' />
<![endif]-->
<script src="../wp-includes/js/jquery/jquery.js-ver=1.12.4-wp" tppabs="http://www.taichi-maker.com/wp-includes/js/jquery/jquery.js?ver=1.12.4-wp"></script>
<script src="../wp-includes/js/jquery/jquery-migrate.min.js-ver=1.4.1" tppabs="http://www.taichi-maker.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1"></script>
<script>
var CrayonSyntaxSettings = {"version":"_2.7.2_beta","is_admin":"0","ajaxurl":"http:\/\/www.taichi-maker.com\/wp-admin\/admin-ajax.php","prefix":"crayon-","setting":"crayon-setting","selected":"crayon-setting-selected","changed":"crayon-setting-changed","special":"crayon-setting-special","orig_value":"data-orig-value","debug":""};
var CrayonSyntaxStrings = {"copy":"Press %s to Copy, %s to Paste","minimize":"Click To Expand Code"};
</script>
<script src="../wp-content/plugins/crayon-syntax-highlighter/js/min/crayon.min.js-ver=_2.7.2_beta" tppabs="http://www.taichi-maker.com/wp-content/plugins/crayon-syntax-highlighter/js/min/crayon.min.js?ver=_2.7.2_beta"></script>
<!--[if lt IE 9]>
<script src="../wp-content/themes/twentysixteen/js/html5.js-ver=3.7.3" tppabs="http://www.taichi-maker.com/wp-content/themes/twentysixteen/js/html5.js?ver=3.7.3"></script>
<![endif]-->
<link rel='https://api.w.org/' href='http://www.taichi-maker.com/wp-json/' />
<meta name="generator" content="WordPress 5.4.4" />
<link rel="canonical" href="http://www.taichi-maker.com/homepage/reference-index/arduino-code-reference/if-else/" />
<link rel='shortlink' href='http://www.taichi-maker.com/?p=631' />
<link rel="alternate" type="application/json+oembed" href="http://www.taichi-maker.com/wp-json/oembed/1.0/embed?url=http%3A%2F%2Fwww.taichi-maker.com%2Fhomepage%2Freference-index%2Farduino-code-reference%2Fif-else%2F" />
<link rel="alternate" type="text/xml+oembed" href="http://www.taichi-maker.com/wp-json/oembed/1.0/embed?url=http%3A%2F%2Fwww.taichi-maker.com%2Fhomepage%2Freference-index%2Farduino-code-reference%2Fif-else%2F&#038;format=xml" />
<style id="custom-background-css">
body.custom-background { background-color: #45989d; }
</style>
	<link rel="icon" href="http://www.taichi-maker.com/wp-content/uploads/2016/04/cropped-taichi_logo-32x32.gif" sizes="32x32" />
<link rel="icon" href="http://www.taichi-maker.com/wp-content/uploads/2016/04/cropped-taichi_logo-192x192.gif" sizes="192x192" />
<link rel="apple-touch-icon" href="http://www.taichi-maker.com/wp-content/uploads/2016/04/cropped-taichi_logo-180x180.gif" />
<meta name="msapplication-TileImage" content="http://www.taichi-maker.com/wp-content/uploads/2016/04/cropped-taichi_logo-270x270.gif" />
</head>

<body class="page-template-default page page-id-631 page-child parent-pageid-137 custom-background wp-embed-responsive">
<div id="page" class="site">
	<div class="site-inner">
		<a class="skip-link screen-reader-text" href="#content">跳至内容</a>

		<header id="masthead" class="site-header" role="banner">
			<div class="site-header-main">
				<div class="site-branding">
					
											<p class="site-title"><a href="../../../../index.htm" tppabs="http://www.taichi-maker.com/" rel="home">太极创客</a></p>
												<p class="site-description">Arduino, ESP8266物联网的应用、开发和学习资料</p>
									</div><!-- .site-branding -->

									<button id="menu-toggle" class="menu-toggle">菜单</button>

					<div id="site-header-menu" class="site-header-menu">
													<nav id="site-navigation" class="main-navigation" role="navigation" aria-label="主菜单">
								<div class="menu-%e7%ab%99%e7%82%b9%e5%af%bc%e8%88%aa-container"><ul id="menu-%e7%ab%99%e7%82%b9%e5%af%bc%e8%88%aa" class="primary-menu"><li id="menu-item-12974" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-12974"><a href="../../../esp8266-nodemcu-iot/iot-tuttorial/index.htm" tppabs="http://www.taichi-maker.com/homepage/esp8266-nodemcu-iot/iot-tuttorial/">物联网教程</a></li>
<li id="menu-item-9850" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-9850"><a href="../../../iot-development/index.htm" tppabs="http://www.taichi-maker.com/homepage/iot-development/">物联网开发</a>
<ul class="sub-menu">
	<li id="menu-item-11246" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-11246"><a href="../../arduino-hardware-refrence/nodemcu/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/nodemcu/">物联网开发板</a></li>
	<li id="menu-item-11247" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-11247"><a href="../../../iot-development/iot-dev-reference/esp8266-iot-dev-ref/index.htm" tppabs="http://www.taichi-maker.com/homepage/iot-development/iot-dev-reference/esp8266-iot-dev-ref/">物联网开发资料</a></li>
	<li id="menu-item-11248" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-11248"><a href="../../../iot-development/iot-platform/index.htm" tppabs="http://www.taichi-maker.com/homepage/iot-development/iot-platform/">物联网平台</a></li>
</ul>
</li>
<li id="menu-item-2325" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-2325"><a href="../../../arduino-tutorial-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/">Arduino 教程</a>
<ul class="sub-menu">
	<li id="menu-item-2326" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-2326"><a href="../../../arduino-basic-tutorial-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-basic-tutorial-index/">1-基础知识篇</a></li>
	<li id="menu-item-2327" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-2327"><a href="../../../arduino-tutorial-index/mearm-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/mearm-index/">2-MeArm篇</a></li>
	<li id="menu-item-2928" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-2928"><a href="../../../arduino-tutorial-index/intelligent-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/intelligent-index/">3-智能应用篇</a></li>
	<li id="menu-item-5241" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-5241"><a href="../../../arduino-tutorial-index/arduino-hardware/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/arduino-hardware/">4- 专项教程篇</a>
	<ul class="sub-menu">
		<li id="menu-item-7145" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-7145"><a href="../../../arduino-tutorial-index/arduino-hardware/index.htm#motor" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/arduino-hardware/#motor">4-1 电机专项</a></li>
		<li id="menu-item-7144" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-7144"><a href="../../../arduino-tutorial-index/arduino-hardware/index.htm#oop" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/arduino-hardware/#oop">4-2 面向对象基础</a></li>
		<li id="menu-item-7141" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-7141"><a href="../../../arduino-tutorial-index/arduino-hardware/index.htm#taile1" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/arduino-hardware/#taile1">4-3 太乐一号</a></li>
	</ul>
</li>
</ul>
</li>
<li id="menu-item-180" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-180"><a href="../../arduino-hardware-refrence/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/">Arduino开发</a>
<ul class="sub-menu">
	<li id="menu-item-9847" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-9847"><a href="../../arduino-hardware-refrence/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/">Arduino开发板</a>
	<ul class="sub-menu">
		<li id="menu-item-3632" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-3632"><a href="../../arduino-hardware-refrence/arduino-purchase-advice/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/arduino-purchase-advice/">Arduino 选购建议</a></li>
		<li id="menu-item-3634" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-3634"><a href="../../arduino-hardware-refrence/arduino-uno/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/arduino-uno/">Arduino Uno 开发板</a></li>
		<li id="menu-item-3635" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-3635"><a href="../../arduino-hardware-refrence/arduino-nano/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/arduino-nano/">Arduino Nano 开发板</a></li>
		<li id="menu-item-3636" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-3636"><a href="../../arduino-hardware-refrence/arduino-mega/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/arduino-mega/">Arduino MEGA 开发板</a></li>
	</ul>
</li>
	<li id="menu-item-11244" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-11244"><a href="../../../arduino-coding-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-coding-index/">Arduino编程</a></li>
	<li id="menu-item-179" class="menu-item menu-item-type-post_type menu-item-object-page current-page-ancestor menu-item-has-children menu-item-179"><a href="../../index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/">Arduino参考资料</a>
	<ul class="sub-menu">
		<li id="menu-item-3967" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-3967"><a href="../../../arduino-coding-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-coding-index/">Arduino编程参考</a>
		<ul class="sub-menu">
			<li id="menu-item-3969" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3969"><a href="../index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-code-reference/">Arduino 语句</a></li>
			<li id="menu-item-11487" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-11487"><a href="../../arduino-library-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-library-index/">Arduino库</a></li>
		</ul>
</li>
		<li id="menu-item-3009" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-3009"><a href="../../communication-reference-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/communication-reference-index/">Arduino通讯</a></li>
		<li id="menu-item-1853" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1853"><a href="../../circuit-reference-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/circuit-reference-index/">电路电机参考</a></li>
		<li id="menu-item-181" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-181"><a href="../../arduino-sensor-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-sensor-index/">传感器应用</a></li>
	</ul>
</li>
</ul>
</li>
<li id="menu-item-11817" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-11817"><a href="../../../arduino-tutorial-structure/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-structure/">教程说明</a></li>
<li id="menu-item-4792" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-4792"><a href="../../../download/index.htm" tppabs="http://www.taichi-maker.com/homepage/download/">下载</a></li>
<li id="menu-item-12002" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-12002"><a href="../../../../faq/index.htm" tppabs="http://www.taichi-maker.com/faq/">常见问题</a></li>
<li id="menu-item-1383" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1383"><a href="../../../../contact-us/index.htm" tppabs="http://www.taichi-maker.com/contact-us/">关于我们</a></li>
</ul></div>							</nav><!-- .main-navigation -->
						
											</div><!-- .site-header-menu -->
							</div><!-- .site-header-main -->

					</header><!-- .site-header -->

		<div id="content" class="site-content">

<div id="primary" class="content-area">
	<main id="main" class="site-main" role="main">
		
<article id="post-631" class="post-631 page type-page status-publish hentry">
	<header class="entry-header">
		<h1 class="entry-title">if…else</h1>	</header><!-- .entry-header -->

	
	<div class="entry-content">
		<h3>说明</h3>
<p>通过if…else语句，用户可以让Arduino判断某一个条件是否达到，并且根据这一判断结果执行相应的程序。</p>
<h3>结构</h3>
<p></p><!-- Crayon Syntax Highlighter v_2.7.2_beta -->

		<div id="crayon-6074eb55de95c263989835" class="crayon-syntax crayon-theme-arduino-ide crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 16px !important;">
		
			<div class="crayon-toolbar" data-settings=" show" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
			<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div><span class="crayon-language">Arduino</span></div></div>
			<div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;"></div>
			<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:6; -o-tab-size:6; -webkit-tab-size:6; tab-size:6; font-size: 12px !important; line-height: 16px !important;">
if( 表达式1 ) {
    语句块1
} else {
    语句块2
}
</textarea></div>
			<div class="crayon-main" style="">
				<table class="crayon-table">
					<tr class="crayon-row">
				<td class="crayon-nums " data-settings="show">
					<div class="crayon-nums-content" style="font-size: 12px !important; line-height: 16px !important;"><div class="crayon-num" data-line="crayon-6074eb55de95c263989835-1">1</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de95c263989835-2">2</div><div class="crayon-num" data-line="crayon-6074eb55de95c263989835-3">3</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de95c263989835-4">4</div><div class="crayon-num" data-line="crayon-6074eb55de95c263989835-5">5</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de95c263989835-6">6</div></div>
				</td>
						<td class="crayon-code"><div class="crayon-pre" style="font-size: 12px !important; line-height: 16px !important; -moz-tab-size:6; -o-tab-size:6; -webkit-tab-size:6; tab-size:6;"><div class="crayon-line" id="crayon-6074eb55de95c263989835-1"><span class="crayon-st">if</span><span class="crayon-sy">(</span><span class="crayon-h"> </span>表达式<span class="crayon-cn">1</span><span class="crayon-h"> </span><span class="crayon-sy">)</span><span class="crayon-h"> </span><span class="crayon-sy">{</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de95c263989835-2"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span>语句块<span class="crayon-cn">1</span></div><div class="crayon-line" id="crayon-6074eb55de95c263989835-3"><span class="crayon-sy">}</span><span class="crayon-h"> </span><span class="crayon-st">else</span><span class="crayon-h"> </span><span class="crayon-sy">{</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de95c263989835-4"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span>语句块<span class="crayon-cn">2</span></div><div class="crayon-line" id="crayon-6074eb55de95c263989835-5"><span class="crayon-sy">}</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de95c263989835-6">&nbsp;</div></div></td>
					</tr>
				</table>
			</div>
		</div>
<!-- [Format Time: 0.0032 seconds] -->
<p>上述结构表示:如果 “表达式1” 的条件得到满足则执行&#8221;语句块1&#8243;。否则Arduino将执行&#8221;语句块2&#8243;。（如下图所示）</p>
<figure id="attachment_633" aria-describedby="caption-attachment-633" style="width: 286px" class="wp-caption alignnone"><a href="../wp-content/uploads/2016/04/if-else.gif" tppabs="http://www.taichi-maker.com/wp-content/uploads/2016/04/if-else.gif"><img class="size-full wp-image-633" src="../wp-content/uploads/2016/04/if-else.gif" tppabs="http://www.taichi-maker.com/wp-content/uploads/2016/04/if-else.gif" alt="if...else语句结构" width="286" height="164"></a><figcaption id="caption-attachment-633" class="wp-caption-text">if&#8230;else语句结构</figcaption></figure>
<p>例:</p><!-- Crayon Syntax Highlighter v_2.7.2_beta -->

		<div id="crayon-6074eb55de965534195385" class="crayon-syntax crayon-theme-arduino-ide crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 16px !important;">
		
			<div class="crayon-toolbar" data-settings=" show" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
			<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div><span class="crayon-language">Arduino</span></div></div>
			<div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;"></div>
			<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:6; -o-tab-size:6; -webkit-tab-size:6; tab-size:6; font-size: 12px !important; line-height: 16px !important;">
if( a == 0 ) {
    digitalWrite(LEDpin, HIGH);
}else {
    digitalWrite(LEDpin, LOW);
}
</textarea></div>
			<div class="crayon-main" style="">
				<table class="crayon-table">
					<tr class="crayon-row">
				<td class="crayon-nums " data-settings="show">
					<div class="crayon-nums-content" style="font-size: 12px !important; line-height: 16px !important;"><div class="crayon-num" data-line="crayon-6074eb55de965534195385-1">1</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de965534195385-2">2</div><div class="crayon-num" data-line="crayon-6074eb55de965534195385-3">3</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de965534195385-4">4</div><div class="crayon-num" data-line="crayon-6074eb55de965534195385-5">5</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de965534195385-6">6</div></div>
				</td>
						<td class="crayon-code"><div class="crayon-pre" style="font-size: 12px !important; line-height: 16px !important; -moz-tab-size:6; -o-tab-size:6; -webkit-tab-size:6; tab-size:6;"><div class="crayon-line" id="crayon-6074eb55de965534195385-1"><span class="crayon-st">if</span><span class="crayon-sy">(</span><span class="crayon-h"> </span><span class="crayon-v">a</span><span class="crayon-h"> </span><span class="crayon-o">==</span><span class="crayon-h"> </span><span class="crayon-cn">0</span><span class="crayon-h"> </span><span class="crayon-sy">)</span><span class="crayon-h"> </span><span class="crayon-sy">{</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de965534195385-2"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">digitalWrite</span><span class="crayon-sy">(</span><span class="crayon-v">LEDpin</span><span class="crayon-sy">,</span><span class="crayon-h"> </span><span class="crayon-k">HIGH</span><span class="crayon-sy">)</span><span class="crayon-sy">;</span></div><div class="crayon-line" id="crayon-6074eb55de965534195385-3"><span class="crayon-sy">}</span><span class="crayon-st">else</span><span class="crayon-h"> </span><span class="crayon-sy">{</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de965534195385-4"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">digitalWrite</span><span class="crayon-sy">(</span><span class="crayon-v">LEDpin</span><span class="crayon-sy">,</span><span class="crayon-h"> </span><span class="crayon-k">LOW</span><span class="crayon-sy">)</span><span class="crayon-sy">;</span></div><div class="crayon-line" id="crayon-6074eb55de965534195385-5"><span class="crayon-sy">}</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de965534195385-6">&nbsp;</div></div></td>
					</tr>
				</table>
			</div>
		</div>
<!-- [Format Time: 0.0002 seconds] -->
<p>在以上示例中，Arduino控制器通过判断变量a是否等于0，从而决定是否执行指令（点亮LED）<br />
<pre>digitalWrite(LEDpin, HIGH);</pre><br />
假如变量a确实等于0，则执行这条指令。否则Arduino将不执行指令：(保持LED熄灭）<br />
<pre>digitalWrite(LEDpin, LOW);</pre></p>
<p><strong>注意：在以上示例的表达式<code>a == 0</code>中，<code>==</code>是关系运算符号，这条语句的作用是让Arduino判断变量a是否等于零。切记不能使用单一等号<code>=</code>。<code>=</code>是赋值符号。<code> a = 0 </code>的含义是给变量a赋值0。</strong></p>
<h4>关系运算符号</h4>
<p>x == y (x 等于 y)<br />
x != y (x 不等于 y)<br />
x &lt; y (x 小于 y)<br />
x &gt; y (x 大于 y)<br />
x &lt;= y (x 小于等于 y)<br />
x &gt;= y (x 大于等于 y)</p>
<h3>if&#8230;else示例程序</h3>
<p>在本示例中，我们将配置Arduino引脚2为输入模式。当开关闭合后，引脚2将获得高电平开关信号，引脚13旁的LED（如下照片红圈所示）将被点亮。反之，该LED为熄灭状态。</p>
<figure id="attachment_388" aria-describedby="caption-attachment-388" style="width: 2524px" class="wp-caption aligncenter"><a href="../wp-content/uploads/2016/04/learn_arduino_uno_r3_L_circled.jpg" tppabs="http://www.taichi-maker.com/wp-content/uploads/2016/04/learn_arduino_uno_r3_L_circled.jpg"><img class="size-full wp-image-388" src="../wp-content/uploads/2016/04/learn_arduino_uno_r3_L_circled.jpg" tppabs="http://www.taichi-maker.com/wp-content/uploads/2016/04/learn_arduino_uno_r3_L_circled.jpg" alt="arduino-uno LED 被标注" width="2524" height="1513" srcset="http://www.taichi-maker.com/wp-content/uploads/2016/04/learn_arduino_uno_r3_L_circled.jpg 2524w, http://www.taichi-maker.com/wp-content/uploads/2016/04/learn_arduino_uno_r3_L_circled-300x180.jpg 300w, http://www.taichi-maker.com/wp-content/uploads/2016/04/learn_arduino_uno_r3_L_circled-768x460.jpg 768w, http://www.taichi-maker.com/wp-content/uploads/2016/04/learn_arduino_uno_r3_L_circled-1024x614.jpg 1024w, http://www.taichi-maker.com/wp-content/uploads/2016/04/learn_arduino_uno_r3_L_circled-1200x719.jpg 1200w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /></a><figcaption id="caption-attachment-388" class="wp-caption-text">Arduino Uno LED 被标注</figcaption></figure>
<p>连接说明（如下图）</p>
<figure id="attachment_466" aria-describedby="caption-attachment-466" style="width: 874px" class="wp-caption aligncenter"><a href="../wp-content/uploads/2016/04/inputPullupButton.jpg" tppabs="http://www.taichi-maker.com/wp-content/uploads/2016/04/inputPullupButton.jpg"><img class="size-full wp-image-466" src="../wp-content/uploads/2016/04/inputPullupButton.jpg" tppabs="http://www.taichi-maker.com/wp-content/uploads/2016/04/inputPullupButton.jpg" alt="Arduino Input Pullup连接方式" width="874" height="664" srcset="http://www.taichi-maker.com/wp-content/uploads/2016/04/inputPullupButton.jpg 874w, http://www.taichi-maker.com/wp-content/uploads/2016/04/inputPullupButton-300x228.jpg 300w, http://www.taichi-maker.com/wp-content/uploads/2016/04/inputPullupButton-768x583.jpg 768w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /></a><figcaption id="caption-attachment-466" class="wp-caption-text">Arduino Input Pullup连接方式</figcaption></figure>
<p><a href="../../../../copy-code-issue/index.htm" tppabs="http://www.taichi-maker.com/copy-code-issue/" rel="noopener" target="_blank">无法复制示例程序代码？</a></p><!-- Crayon Syntax Highlighter v_2.7.2_beta -->

		<div id="crayon-6074eb55de968555019126" class="crayon-syntax crayon-theme-arduino-ide crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 16px !important;">
		
			<div class="crayon-toolbar" data-settings=" show" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><span class="crayon-title"></span>
			<div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;"><div class="crayon-button crayon-nums-button" title="Toggle Line Numbers"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-plain-button" title="Toggle Plain Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-wrap-button" title="Toggle Line Wrap"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-expand-button" title="Expand Code"><div class="crayon-button-icon"></div></div><div class="crayon-button crayon-popup-button" title="Open Code In New Window"><div class="crayon-button-icon"></div></div><span class="crayon-language">Arduino</span></div></div>
			<div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;"></div>
			<div class="crayon-plain-wrap"><textarea wrap="soft" class="crayon-plain print-no" data-settings="dblclick" readonly style="-moz-tab-size:6; -o-tab-size:6; -webkit-tab-size:6; tab-size:6; font-size: 12px !important; line-height: 16px !important;">
/*
if...else示例程序
v1.0
Created 2016
by 太极创客
www.taichi-maker.com

说明：
本程序旨在演示如何使用if...else语句。
在本示例中，当按钮被按下后，引脚13旁的LED将会点亮。
获得具体连接电路图，请参阅太极创客网站。
  
This example code is in the public domain.
*/

void setup() {
  Serial.begin(9600);   //开始串口通讯
  pinMode(2, INPUT_PULLUP);    //将引脚2设置为输入上拉模式
  pinMode(13, OUTPUT);
}

void loop() {
  int sensorVal = digitalRead(2);  //将开关状态数值读取到变量中
  Serial.println(sensorVal);  //输出开关状态数值

  //请留意在上拉模式下，按钮的逻辑状态是反的。
  //即：开关断开时引脚读取到高电平。开关被按下后引脚读取到低电平。
  //按钮被按下后，引脚13连接的LED将被点亮。按钮没有按下时，LED熄灭。
  
  //如果按钮没有按下，熄灭LED。否则，点亮LED
    
  if (sensorVal == HIGH) {  //按钮没有按下
    digitalWrite(13, LOW);  //熄灭LED
  } else {                  //否则
    digitalWrite(13, HIGH); //点亮LED
  }
}</textarea></div>
			<div class="crayon-main" style="">
				<table class="crayon-table">
					<tr class="crayon-row">
				<td class="crayon-nums " data-settings="show">
					<div class="crayon-nums-content" style="font-size: 12px !important; line-height: 16px !important;"><div class="crayon-num" data-line="crayon-6074eb55de968555019126-1">1</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-2">2</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-3">3</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-4">4</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-5">5</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-6">6</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-7">7</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-8">8</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-9">9</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-10">10</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-11">11</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-12">12</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-13">13</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-14">14</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-15">15</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-16">16</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-17">17</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-18">18</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-19">19</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-20">20</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-21">21</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-22">22</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-23">23</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-24">24</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-25">25</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-26">26</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-27">27</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-28">28</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-29">29</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-30">30</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-31">31</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-32">32</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-33">33</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-34">34</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-35">35</div><div class="crayon-num crayon-striped-num" data-line="crayon-6074eb55de968555019126-36">36</div><div class="crayon-num" data-line="crayon-6074eb55de968555019126-37">37</div></div>
				</td>
						<td class="crayon-code"><div class="crayon-pre" style="font-size: 12px !important; line-height: 16px !important; -moz-tab-size:6; -o-tab-size:6; -webkit-tab-size:6; tab-size:6;"><div class="crayon-line" id="crayon-6074eb55de968555019126-1"><span class="crayon-c">/*</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-2"><span class="crayon-c">if...else示例程序</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-3"><span class="crayon-c">v1.0</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-4"><span class="crayon-c">Created 2016</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-5"><span class="crayon-c">by 太极创客</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-6"><span class="crayon-c">www.taichi-maker.com</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-7">&nbsp;</div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-8"><span class="crayon-c">说明：</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-9"><span class="crayon-c">本程序旨在演示如何使用if...else语句。</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-10"><span class="crayon-c">在本示例中，当按钮被按下后，引脚13旁的LED将会点亮。</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-11"><span class="crayon-c">获得具体连接电路图，请参阅太极创客网站。</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-12"><span class="crayon-c">&nbsp;&nbsp;</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-13"><span class="crayon-c">This example code is in the public domain.</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-14"><span class="crayon-c">*/</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-15">&nbsp;</div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-16"><span class="crayon-t">void</span><span class="crayon-h"> </span><span class="crayon-st">setup</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span><span class="crayon-h"> </span><span class="crayon-sy">{</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-17"><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-st">Serial</span><span class="crayon-sy">.</span><span class="crayon-v">begin</span><span class="crayon-sy">(</span><span class="crayon-cn">9600</span><span class="crayon-sy">)</span><span class="crayon-sy">;</span><span class="crayon-h">&nbsp;&nbsp; </span><span class="crayon-c">//开始串口通讯</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-18"><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-st">pinMode</span><span class="crayon-sy">(</span><span class="crayon-cn">2</span><span class="crayon-sy">,</span><span class="crayon-h"> </span><span class="crayon-k">INPUT_PULLUP</span><span class="crayon-sy">)</span><span class="crayon-sy">;</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-c">//将引脚2设置为输入上拉模式</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-19"><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-st">pinMode</span><span class="crayon-sy">(</span><span class="crayon-cn">13</span><span class="crayon-sy">,</span><span class="crayon-h"> </span><span class="crayon-k">OUTPUT</span><span class="crayon-sy">)</span><span class="crayon-sy">;</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-20"><span class="crayon-sy">}</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-21">&nbsp;</div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-22"><span class="crayon-t">void</span><span class="crayon-h"> </span><span class="crayon-st">loop</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span><span class="crayon-h"> </span><span class="crayon-sy">{</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-23"><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-r">int</span><span class="crayon-h"> </span><span class="crayon-v">sensorVal</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-st">digitalRead</span><span class="crayon-sy">(</span><span class="crayon-cn">2</span><span class="crayon-sy">)</span><span class="crayon-sy">;</span><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-c">//将开关状态数值读取到变量中</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-24"><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-st">Serial</span><span class="crayon-sy">.</span><span class="crayon-e">println</span><span class="crayon-sy">(</span><span class="crayon-v">sensorVal</span><span class="crayon-sy">)</span><span class="crayon-sy">;</span><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-c">//输出开关状态数值</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-25">&nbsp;</div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-26"><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-c">//请留意在上拉模式下，按钮的逻辑状态是反的。</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-27"><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-c">//即：开关断开时引脚读取到高电平。开关被按下后引脚读取到低电平。</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-28"><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-c">//按钮被按下后，引脚13连接的LED将被点亮。按钮没有按下时，LED熄灭。</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-29"><span class="crayon-h">&nbsp;&nbsp;</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-30"><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-c">//如果按钮没有按下，熄灭LED。否则，点亮LED</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-31"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-32"><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-st">if</span><span class="crayon-h"> </span><span class="crayon-sy">(</span><span class="crayon-v">sensorVal</span><span class="crayon-h"> </span><span class="crayon-o">==</span><span class="crayon-h"> </span><span class="crayon-k">HIGH</span><span class="crayon-sy">)</span><span class="crayon-h"> </span><span class="crayon-sy">{</span><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-c">//按钮没有按下</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-33"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">digitalWrite</span><span class="crayon-sy">(</span><span class="crayon-cn">13</span><span class="crayon-sy">,</span><span class="crayon-h"> </span><span class="crayon-k">LOW</span><span class="crayon-sy">)</span><span class="crayon-sy">;</span><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-c">//熄灭LED</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-34"><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-sy">}</span><span class="crayon-h"> </span><span class="crayon-st">else</span><span class="crayon-h"> </span><span class="crayon-sy">{</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-c">//否则</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-35"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">digitalWrite</span><span class="crayon-sy">(</span><span class="crayon-cn">13</span><span class="crayon-sy">,</span><span class="crayon-h"> </span><span class="crayon-k">HIGH</span><span class="crayon-sy">)</span><span class="crayon-sy">;</span><span class="crayon-h"> </span><span class="crayon-c">//点亮LED</span></div><div class="crayon-line crayon-striped-line" id="crayon-6074eb55de968555019126-36"><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-sy">}</span></div><div class="crayon-line" id="crayon-6074eb55de968555019126-37"><span class="crayon-sy">}</span></div></div></td>
					</tr>
				</table>
			</div>
		</div>
<!-- [Format Time: 0.0006 seconds] -->
<p>相关阅读：<a href="../switch-case/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-code-reference/switch-case/" target="_blank" rel="noopener">switch case</a>, <a href="../if/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-code-reference/if/" target="_blank" rel="noopener">if</a></p>
	</div><!-- .entry-content -->

	
</article><!-- #post-631 -->

	</main><!-- .site-main -->

	<aside id="content-bottom-widgets" class="content-bottom-widgets" role="complementary">
			<div class="widget-area">
			<section id="text-2" class="widget widget_text"><h2 class="widget-title">太极创客 微信公众号</h2>			<div class="textwidget"><p><img class="alignnone" src="../wp-content/uploads/2017/04/wechat-code128.gif" tppabs="http://www.taichi-maker.com/wp-content/uploads/2017/04/wechat-code128.gif" alt="太极创客-微信公众号" /></p>
<h3><a href="javascript:if(confirm('https://beian.miit.gov.cn/  \n\n??ļ????? Teleport Ultra ??, ?Ϊ ??һ???????????????Ϊ?????????ĵ????  \n\n????????????'))window.location='https://beian.miit.gov.cn/'" tppabs="https://beian.miit.gov.cn/" target="_blank" rel="noopener noreferrer"><strong>京ICP备15021217号-5</strong></a></h3>
</div>
		</section>		</div><!-- .widget-area -->
	
			<div class="widget-area">
			<section id="text-13" class="widget widget_text"><h2 class="widget-title">太极创客 官方微博</h2>			<div class="textwidget"><p><img class="size-full wp-image-1984" src="../wp-content/uploads/2017/04/weibo-code128.gif" tppabs="http://www.taichi-maker.com/wp-content/uploads/2017/04/weibo-code128.gif" alt="太极创客 官方微博 二维码" width="128" height="128" /></p>
</div>
		</section>		</div><!-- .widget-area -->
	</aside><!-- .content-bottom-widgets -->

</div><!-- .content-area -->


	<aside id="secondary" class="sidebar widget-area" role="complementary">
		<section id="search-2" class="widget widget_search">
<form role="search" method="get" class="search-form" action="http://www.taichi-maker.com/">
	<label>
		<span class="screen-reader-text">搜索：</span>
		<input type="search" class="search-field" placeholder="搜索…" value="" name="s" />
	</label>
	<button type="submit" class="search-submit"><span class="screen-reader-text">搜索</span></button>
</form>
</section><section id="custom_html-2" class="widget_text widget widget_custom_html"><div class="textwidget custom-html-widget"><table style="border: none;" width="100%" cellspacing="0" cellpadding="5">
<tbody>
<tr>
<td style="border: none; text-align: center;" valign="top" width="100%">
<img src="../wp-content/uploads/2019/03/QQ-group-QR-w-words.png" tppabs="http://www.taichi-maker.com/wp-content/uploads/2019/03/QQ-group-QR-w-words.png" alt="太极创客学习交流QQ群二维码" width="300" height="300" class="size-full wp-image-6726" />
</td>
</tr>
</tbody>
</table></div></section><section id="custom_html-3" class="widget_text widget widget_custom_html"><div class="textwidget custom-html-widget"><table style="border: none;" width="100%" cellspacing="0" cellpadding="5">
<tbody>
<tr>
<td style="border: none; text-align: center;" valign="top" width="100%">
<img src="../wp-content/uploads/2019/11/QQ-group-QR-2.jpg" tppabs="http://www.taichi-maker.com/wp-content/uploads/2019/11/QQ-group-QR-2.jpg" alt="太极创客学习交流QQ群二维码" width="300" height="300" class="size-full wp-image-6726" />
</td>
</tr>
</tbody>
</table></div></section><section id="text-12" class="widget widget_text"><h2 class="widget-title">联系我们</h2>			<div class="textwidget"><p>假如您对网站内容有任何意见和建议，请发邮件到：<br />
<a href="mailto:taichimaker@163.com">taichimaker@163.com</a><br />
或者通过太极创客的社交媒体平台<a href="../../../../contact-us/index.htm" tppabs="http://www.taichi-maker.com/contact-us/">与我们互动</a></p>
</div>
		</section><section id="text-14" class="widget widget_text"><h2 class="widget-title">版权声明</h2>			<div class="textwidget"><p><span style="color: #d3552d;"><strong>本网站访问者可将本网站提供的内容或服务用于个人学习研究以及其他非商业性或非盈利性用途。除此以外,将本网站任何内容（包括图片，文字，视频，程序代码，电路设计）或服务用于任何商业或盈利用途时,须征得本网站及相关权利人的书面许可。</strong></span></p>
</div>
		</section>	</aside><!-- .sidebar .widget-area -->

		</div><!-- .site-content -->

		<footer id="colophon" class="site-footer" role="contentinfo">
							<nav class="main-navigation" role="navigation" aria-label="页脚主菜单">
					<div class="menu-%e7%ab%99%e7%82%b9%e5%af%bc%e8%88%aa-container"><ul id="menu-%e7%ab%99%e7%82%b9%e5%af%bc%e8%88%aa-1" class="primary-menu"><li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-12974"><a href="../../../esp8266-nodemcu-iot/iot-tuttorial/index.htm" tppabs="http://www.taichi-maker.com/homepage/esp8266-nodemcu-iot/iot-tuttorial/">物联网教程</a></li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-9850"><a href="../../../iot-development/index.htm" tppabs="http://www.taichi-maker.com/homepage/iot-development/">物联网开发</a>
<ul class="sub-menu">
	<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-11246"><a href="../../arduino-hardware-refrence/nodemcu/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/nodemcu/">物联网开发板</a></li>
	<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-11247"><a href="../../../iot-development/iot-dev-reference/esp8266-iot-dev-ref/index.htm" tppabs="http://www.taichi-maker.com/homepage/iot-development/iot-dev-reference/esp8266-iot-dev-ref/">物联网开发资料</a></li>
	<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-11248"><a href="../../../iot-development/iot-platform/index.htm" tppabs="http://www.taichi-maker.com/homepage/iot-development/iot-platform/">物联网平台</a></li>
</ul>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-2325"><a href="../../../arduino-tutorial-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/">Arduino 教程</a>
<ul class="sub-menu">
	<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-2326"><a href="../../../arduino-basic-tutorial-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-basic-tutorial-index/">1-基础知识篇</a></li>
	<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-2327"><a href="../../../arduino-tutorial-index/mearm-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/mearm-index/">2-MeArm篇</a></li>
	<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-2928"><a href="../../../arduino-tutorial-index/intelligent-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/intelligent-index/">3-智能应用篇</a></li>
	<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-5241"><a href="../../../arduino-tutorial-index/arduino-hardware/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/arduino-hardware/">4- 专项教程篇</a>
	<ul class="sub-menu">
		<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-7145"><a href="../../../arduino-tutorial-index/arduino-hardware/index.htm#motor" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/arduino-hardware/#motor">4-1 电机专项</a></li>
		<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-7144"><a href="../../../arduino-tutorial-index/arduino-hardware/index.htm#oop" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/arduino-hardware/#oop">4-2 面向对象基础</a></li>
		<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-7141"><a href="../../../arduino-tutorial-index/arduino-hardware/index.htm#taile1" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-index/arduino-hardware/#taile1">4-3 太乐一号</a></li>
	</ul>
</li>
</ul>
</li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-180"><a href="../../arduino-hardware-refrence/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/">Arduino开发</a>
<ul class="sub-menu">
	<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-9847"><a href="../../arduino-hardware-refrence/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/">Arduino开发板</a>
	<ul class="sub-menu">
		<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-3632"><a href="../../arduino-hardware-refrence/arduino-purchase-advice/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/arduino-purchase-advice/">Arduino 选购建议</a></li>
		<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-3634"><a href="../../arduino-hardware-refrence/arduino-uno/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/arduino-uno/">Arduino Uno 开发板</a></li>
		<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-3635"><a href="../../arduino-hardware-refrence/arduino-nano/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/arduino-nano/">Arduino Nano 开发板</a></li>
		<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-3636"><a href="../../arduino-hardware-refrence/arduino-mega/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-hardware-refrence/arduino-mega/">Arduino MEGA 开发板</a></li>
	</ul>
</li>
	<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-11244"><a href="../../../arduino-coding-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-coding-index/">Arduino编程</a></li>
	<li class="menu-item menu-item-type-post_type menu-item-object-page current-page-ancestor menu-item-has-children menu-item-179"><a href="../../index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/">Arduino参考资料</a>
	<ul class="sub-menu">
		<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-3967"><a href="../../../arduino-coding-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-coding-index/">Arduino编程参考</a>
		<ul class="sub-menu">
			<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3969"><a href="../index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-code-reference/">Arduino 语句</a></li>
			<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-11487"><a href="../../arduino-library-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-library-index/">Arduino库</a></li>
		</ul>
</li>
		<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-3009"><a href="../../communication-reference-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/communication-reference-index/">Arduino通讯</a></li>
		<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1853"><a href="../../circuit-reference-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/circuit-reference-index/">电路电机参考</a></li>
		<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-181"><a href="../../arduino-sensor-index/index.htm" tppabs="http://www.taichi-maker.com/homepage/reference-index/arduino-sensor-index/">传感器应用</a></li>
	</ul>
</li>
</ul>
</li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-11817"><a href="../../../arduino-tutorial-structure/index.htm" tppabs="http://www.taichi-maker.com/homepage/arduino-tutorial-structure/">教程说明</a></li>
<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-4792"><a href="../../../download/index.htm" tppabs="http://www.taichi-maker.com/homepage/download/">下载</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-post menu-item-12002"><a href="../../../../faq/index.htm" tppabs="http://www.taichi-maker.com/faq/">常见问题</a></li>
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-1383"><a href="../../../../contact-us/index.htm" tppabs="http://www.taichi-maker.com/contact-us/">关于我们</a></li>
</ul></div>				</nav><!-- .main-navigation -->
			
			
			<div class="site-info">
								<span class="site-title"><a href="../../../../index.htm" tppabs="http://www.taichi-maker.com/" rel="home">太极创客</a></span>
								<a href="javascript:if(confirm('https://cn.wordpress.org/  \n\n??ļ????? Teleport Ultra ??, ?Ϊ ??һ???????????????Ϊ?????????ĵ????  \n\n????????????'))window.location='https://cn.wordpress.org/'" tppabs="https://cn.wordpress.org/" class="imprint">
					自豪地采用WordPress				</a>
			</div><!-- .site-info -->
		</footer><!-- .site-footer -->
	</div><!-- .site-inner -->
</div><!-- .site -->

<script src="../wp-content/themes/twentysixteen/js/skip-link-focus-fix.js-ver=20170530" tppabs="http://www.taichi-maker.com/wp-content/themes/twentysixteen/js/skip-link-focus-fix.js?ver=20170530"></script>
<script>
var screenReaderText = {"expand":"\u5c55\u5f00\u5b50\u83dc\u5355","collapse":"\u6298\u53e0\u5b50\u83dc\u5355"};
</script>
<script src="../wp-content/themes/twentysixteen/js/functions.js-ver=20181217" tppabs="http://www.taichi-maker.com/wp-content/themes/twentysixteen/js/functions.js?ver=20181217"></script>
<script src="../wp-includes/js/wp-embed.min.js-ver=5.4.4" tppabs="http://www.taichi-maker.com/wp-includes/js/wp-embed.min.js?ver=5.4.4"></script>
	<script type="text/javascript">
        jQuery(document).ready(function ($) {
            //$( document ).ajaxStart(function() {
            //});

			
            for (var i = 0; i < document.forms.length; ++i) {
                var form = document.forms[i];
				if ($(form).attr("method") != "get") { $(form).append('<input type="hidden" name="cdUOAfpIk_Dm" value="nzPAGvymo5Fl" />'); }
if ($(form).attr("method") != "get") { $(form).append('<input type="hidden" name="XlVPCaZf_WA" value="VyntA.h3HuX" />'); }
if ($(form).attr("method") != "get") { $(form).append('<input type="hidden" name="LYDGtx_A" value="qSQ9k@In" />'); }
            }

			
            $(document).on('submit', 'form', function () {
				if ($(this).attr("method") != "get") { $(this).append('<input type="hidden" name="cdUOAfpIk_Dm" value="nzPAGvymo5Fl" />'); }
if ($(this).attr("method") != "get") { $(this).append('<input type="hidden" name="XlVPCaZf_WA" value="VyntA.h3HuX" />'); }
if ($(this).attr("method") != "get") { $(this).append('<input type="hidden" name="LYDGtx_A" value="qSQ9k@In" />'); }
                return true;
            });

			
            jQuery.ajaxSetup({
                beforeSend: function (e, data) {

                    //console.log(Object.getOwnPropertyNames(data).sort());
                    //console.log(data.type);

                    if (data.type !== 'POST') return;

                    if (typeof data.data === 'object' && data.data !== null) {
						data.data.append("cdUOAfpIk_Dm", "nzPAGvymo5Fl");
data.data.append("XlVPCaZf_WA", "VyntA.h3HuX");
data.data.append("LYDGtx_A", "qSQ9k@In");
                    }
                    else {
                        data.data =  data.data + '&cdUOAfpIk_Dm=nzPAGvymo5Fl&XlVPCaZf_WA=VyntA.h3HuX&LYDGtx_A=qSQ9k@In';
                    }
                }
            });

        });
	</script>
	</body>
</html>
